using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using GameStateManagement;

namespace Frogger_Game
{
    /// <summary>
    /// Game main class
    /// </summary>
    ///  
   
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        // class variables
        public GraphicsDeviceManager graphics;

        //static class variables (to be shared among the game components)
        public static bool isPaused = false;
        public static int musicVolume = 5;
        public static int effectsVolume = 5;
        public static bool isWaiting = false;

        //Game constructor
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            this.Services.AddService(typeof(GraphicsDeviceManager), graphics);
            graphics.IsFullScreen = false;
            Content.RootDirectory = "Content";
        }



        /// <summary>
        /// Initialize all non-graphics elements
        /// </summary>
        protected override void Initialize()
        {
            // We need to add Sound as the first component (see Sound component class for further explanations)
            this.Components.Add(new Sound(this));
#if XBOX
            //We add the GameServicesComponent, necessary to load/save game in Xbox360 console.
            this.Components.Add(new GamerServicesComponent(this));
#endif
            this.Components.Add(new Input(this));

            //The first screen to be shown is the Main Menu
            this.Components.Add(new Main_Menu(this));
           base.Initialize();
        }


        /// <summary>
        /// Load all graphics content here
        /// </summary>
        protected override void LoadContent()
        {
            graphics.PreferredBackBufferWidth = this.GraphicsDevice.Adapter.CurrentDisplayMode.Width;
            graphics.PreferredBackBufferHeight = this.GraphicsDevice.Adapter.CurrentDisplayMode.Height;
            graphics.ApplyChanges();

            MapGrid.getScreenRatio(graphics.GraphicsDevice.Viewport.AspectRatio);
        }

        /// <summary>
        /// Update method
        /// </summary>
        /// <param name="gameTime">Fornisce uno snapshot dei valori di temporizzazione.</param>
        protected override void Update(GameTime gameTime)
        {

            // Allows to exit the game
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            KeyboardState keyboard = Keyboard.GetState();

            if (keyboard.IsKeyDown(Keys.F4))
                this.Exit();

            base.Update(gameTime);
        }
        
        /// <summary>
        /// Draw method
        /// </summary>
        /// <param name="gameTime">Time of the game</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            base.Draw(gameTime);
        }

        protected override void Dispose(bool disposing)
        {
            this.Services.RemoveService(typeof(GraphicsDeviceManager));
            base.Dispose(disposing);
        }
    }
}
